package com.intellagric.controller.storage;

import com.intellagric.common.bean.LayuiDataGridResult;
import com.intellagric.common.bean.ResponseMessage;
import com.intellagric.common.utils.UUIDUtils;
import com.intellagric.interfaces.storage.StorageService;
import com.intellagric.pojo.Storage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/admin")
public class StorageController {

    @Autowired
    private StorageService StorageService;

    @RequestMapping("/storage/add")
    @ResponseBody
    public ResponseMessage addStorage(Storage Storage){
        Storage.setStorageId(UUIDUtils.getID());
        return StorageService.insertStorage(Storage);
    }

    @RequestMapping("/storage/edit")
    @ResponseBody
    public ResponseMessage editStorage(Storage Storage){
        return StorageService.editStorage(Storage);
    }

    @RequestMapping("/storage/delete")
    @ResponseBody
    public ResponseMessage deleteStorage(String id){
        return StorageService.deleteStorage(id);
    }

    @RequestMapping("/storage/batchdelete")
    @ResponseBody
    public LayuiDataGridResult batchDelete(@RequestParam("ids[]") String[] ids){
        return StorageService.batchDeleteStorage(ids);
    }

    @RequestMapping("/storage/getStorage")
    @ResponseBody
    public Storage getStorage(String StorageId){
        return (Storage) StorageService.selectStorageById(StorageId).getData().get("storageBean");
    }

    @RequestMapping("/storage/tree")
    @ResponseBody
    public LayuiDataGridResult getMenu(){
        return StorageService.getMenu();
    }



    @RequestMapping("/storage/search")
    @ResponseBody
    public LayuiDataGridResult search(int page, int limit, String keyword){
        return StorageService.getStorageByKeyword(page,limit,keyword);
    }
    /**
     * 查询菜单树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/storage/treelist")
    @ResponseBody
    public List<Storage> getTreeList() {
        LayuiDataGridResult category=StorageService.getMenu();
        return category.getData();
    }


}
